# -- coding: utf-8 --

from sys import argv
from os.path import exists

script, in_file, out_file = argv

print(f"The {script} will copy the contents of {in_file} to {out_file}.")

in_file_handler = open(in_file)
data = in_file_handler.read()
in_file_handler.close()

print(f"The input file is {len(data)} bytes long.")

overwritten = False
out_file_exist = False
create = True
if exists(out_file):
	print(f"[WARNING] The destination file {out_file} is now exsited! Do you want to overwrite it?")
	overwritten = True if input('> ') == 'yes' else False

	if not overwritten:
		print(f"Will you [append] the content to {out_file}, or [create] a new file to write?")
		if(input('> ') == 'append'):
			create = False
		else:
			out_file_exist = True
			create = True

if overwritten:
	out_file_handler = open(out_file, 'w+')
	out_file_handler.write(data)
	print("Copying file done!")
	out_file_handler.close()

else:
	if not create:
		out_file_handler = open(out_file, 'a+')
		out_file_handler.write(data)
		print("Appending file done!")
		out_file_handler.close()
	else:
		if out_file_exist:
			out_file = input("specify the new file name: ")
		out_file_handler = open(out_file, 'w+')
		out_file_handler.write(data)
		print("Creating and coping done!")
		out_file_handler.close()

